﻿@using Webdiyer.WebControls.Mvc
@model PagedList<NationalIT.EscrowLoan>
<div class="row-fluid">
    <div class="span12">
        <div class="box">
            <div class="box-title">
                <h3>
                    <i class="icon-table"></i>List EscrowLoan @ViewBag.ForDriver @ViewBag.ForOwner</h3>
            </div>
            <div class="box-content">
                <div class="row-fluid">
                    <div class="span12">
                        @Html.Partial("_MenuButtonNewEditOrDelete")
                    </div>
                </div>
                <table class="table table-advance">
                    <tr>
                        <th>
                            <input type="checkbox" name="" value="" class="checkAll" />
                        </th>
                        <th>
                            Expenses
                        </th>
                        <th>
                            TotalAmount
                        </th>
                        <th>
                            AmountPaid
                        </th>
                        <th>
                            Balance
                        </th>
                        <th>
                            Owner/Driver
                        </th>
                        <th>
                            Owner/Driver name
                        </th>
                    </tr>
                    @foreach (var item in Model)
                    {
                        <tr>
                            <td>
                                <input type="checkbox" name="checkOwner" value="@item.ID" class="checkitem"/>
                            </td>
                            <td>
                                @Html.ActionLink(item.Expenses+" ", "NewOrEdit", new { id = item.ID })
                            </td>
                            <td>
                                @String.Format("{0:C}", item.TotalAmount)
                            </td>
                            <td>
                                @String.Format("{0:C}", item.AmountPaid)
                            </td>
                            <td>
                                @String.Format("{0:C}", item.Balance)
                            </td>
                            <td>
                                @(item.Owner ? "Owner" : "Driver")
                            </td>
                            <td>
                                @{
                           
                            if (!item.Owner)
                            {
                                var driver = NationalIT.DB.Entities.Driver_Info.FirstOrDefault(m => m.ID == item.OwnerDriver);
                                if (driver != null)
                                {
                                    <span>@driver.Last_name @driver.First_name</span>
                                }
                            }
                            else
                            {
                                var owner = NationalIT.DB.Entities.Owners.FirstOrDefault(m => m.OwnerID == item.OwnerDriver);
                                if (owner != null)
                                {
                                    <span>@owner.Name</span>
                                }
                            }

                                }
                                
                            </td>
                        </tr>
                    }
                </table>
                <div class="row-fluid">
                    <div class="span4">
                        <div class="dataTables_info">
                            @if (Model.TotalItemCount > 0)
                            {
                                if (Model.TotalItemCount < Model.PageSize)
                                {
                                <span>1 </span>
                                <span>- </span>@Model.TotalItemCount
                                }
                                else
                                {
                                <span></span>@((Model.CurrentPageIndex - 1) * Model.PageSize + 1)
                                <span>- </span>@((Model.CurrentPageIndex != Model.TotalPageCount) ? (Model.CurrentPageIndex * Model.PageSize) : Math.Abs((Model.CurrentPageIndex) * Model.PageSize - (Model.PageSize * Model.TotalPageCount) - Model.TotalItemCount))
                                }
                                <span>of </span>@(Model.TotalItemCount)
                            
                            }
                        </div>
                    </div>
                    <div class="span8">
                        <div class="dataTables_paginate paging_bootstrap pagination phantrangmvcpager">
                            @* <ul>
                        <li class="prev disabled"><a href="#">← Prev</a></li><li class="active"><a href="#">
                            1</a></li><li><a href="#">2</a></li><li class="next"><a href="#">Next → </a>
                        </li>
                    </ul>*@
                            @Html.Pager(Model, new PagerOptions { ContainerTagName = "ul", PageIndexParameterName = "page", CurrentPagerItemWrapperFormatString = "<li class='active'>{0}</li>", CurrentPageNumberFormatString = "{0}", FirstPageText = "&laquo; ", LastPageText = " &raquo;", NextPageText = "Next →", PrevPageText = "← Prev", SeparatorHtml = "" })
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
